class MembersSweeper < ActionController::Caching::Sweeper
  observe Member # This sweeper is going to keep an eye on the Member model

  # If our sweeper detects that a Member was saved call this
  def after_save(member)
    expire_cache_for(member)
  end

  # If our sweeper detects that a Member was deleted call this
  def after_destroy(member)
    expire_cache_for(member)
  end
  
  private
  def expire_cache_for(member)
    expire_cache
    # caller[0]=~/`(.*?)'/  # note the first quote is a backtick
    # puts $1 + " members"
  end
  
  def expire_cache
    expire_fragment(%r(members/list\?action_suffix=list_.*))
    expire_fragment(%r(members/list\?action_suffix=emails_.*))
  end
end
